﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 酒店管理
{
    partial class 更换房间 : Form
    {
        string oldRoom;//原房间号
        string custID;
        string bill;//需转移的登记入住账单号
        //string newPrice;//提示需要输入的新房价,记录到入住表中的实际房价
        DataSet tmpDS;
        database tmpDB;


        public 更换房间(string oldRoomID, string CID, string payBill, ref DataSet DS, ref database DB)
        {
            InitializeComponent();
            oldRoom = oldRoomID;
            custID = CID;
            bill = payBill;
            tmpDS = DS;
            tmpDB = DB;
            string sql = "select 客户编号,实际房价 from 登记入住 where 房间号='" + oldRoom + "' AND 客户编号='" + custID + "'";
            tmpDB.SelectCMD(sql, ref tmpDS);
            DataTable tmpdt = tmpDS.Tables["Buffer"];
            oldRoom = tmpdt.Rows[0][0].ToString();
            textBox1.Text = tmpdt.Rows[0][0].ToString();//标记原房号
            textBox2.Text = tmpdt.Rows[0][1].ToString();//标记原房价
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string remain;//用于记录当前房间剩下的住户，如果等于0则表示可置脏房
            string sql;
            if (MessageBox.Show("确认要将从[" + oldRoom + "]换房到[" + textBox3.Text + "]吗?", "换房确认", MessageBoxButtons.YesNo) == DialogResult.No) return; 
  
            //更改入住中对应房间号和客户编号项的实际房价和原项的房号
            sql = "update 登记入住 set 房间号='" + textBox3.Text + "',实际房价='" + textBox4.Text + "' where 房间号='" + oldRoom + "' AND 客户编号='" + custID + "'";
            tmpDB.UpdateCMD(sql, ref tmpDS);
            //转移房间消费信息
            sql = "update 房间消费 set 房间号='" + textBox3.Text + "' where 房间号='" + oldRoom + "' AND 客户编号='" + custID + "'";
            tmpDB.UpdateCMD(sql, ref tmpDS);
            //更改房间状态,考虑是否未住满房
            sql = "select sum(*) from 登记入住 where 房间号='" + oldRoom + "'";
            tmpDB.SelectCMD(sql, ref tmpDS);
            DataTable tmpdt = tmpDS.Tables["Buffer"];
            remain = tmpdt.Rows[0][0].ToString();//读出该房间剩余客人数
            if ("0" != remain) return;
            sql = "update 房间 set 房间状态='脏房' where 房间号='" + oldRoom + "'";
            tmpDB.UpdateCMD(sql, ref tmpDS);
        }
    }
}